using System;
using System.Data;
namespace Rogan.Data
{
	public class DBTypeConversion
	{
		private static string[,] DBTypeConversionKey;
		public static SqlDbType SystemTypeToDbType(Type sourceType)
		{
			string value = sourceType.ToString();
			string text = string.Empty;
			int length = DBTypeConversionKey.GetLength(0);
			for (int i = 0; i < length; i++)
			{
				if (DBTypeConversionKey[i, 1].Equals(value))
				{
					text = DBTypeConversionKey[i, 0];
				}
			}
			if (text == string.Empty)
			{
				text = "Variant";
			}
			return (SqlDbType)Enum.Parse(typeof(SqlDbType), text);
		}
		public static Type DbTypeToSystemType(SqlDbType sourceType)
		{
			string text = string.Empty;
			string value = sourceType.ToString();
			int length = DBTypeConversionKey.GetLength(0);
			for (int i = 0; i < length; i++)
			{
				if (DBTypeConversionKey[i, 0].Equals(value))
				{
					text = DBTypeConversionKey[i, 1];
				}
			}
			if (text == string.Empty)
			{
				text = "System.Object";
			}
			return Type.GetType(text);
		}
		public static DbType GetDbType(Type type)
		{
			string name = type.Name;
			DbType result = DbType.String;
			try
			{
				result = (DbType)Enum.Parse(typeof(DbType), name, true);
			}
			catch (Exception)
			{
			}
			return result;
		}
		static DBTypeConversion()
		{
			// Note: this type is marked as 'beforefieldinit'.
			string[,] array = new string[24, 2];
			array[0, 0] = "BigInt";
			array[0, 1] = "System.Int64";
			array[1, 0] = "Binary";
			array[1, 1] = "System.Byte[]";
			array[2, 0] = "Bit";
			array[2, 1] = "System.Boolean";
			array[3, 0] = "Char";
			array[3, 1] = "System.String";
			array[4, 0] = "DateTime";
			array[4, 1] = "System.DateTime";
			array[5, 0] = "Decimal";
			array[5, 1] = "System.Decimal";
			array[6, 0] = "Float";
			array[6, 1] = "System.Double";
			array[7, 0] = "Image";
			array[7, 1] = "System.Byte[]";
			array[8, 0] = "Int";
			array[8, 1] = "System.Int32";
			array[9, 0] = "Money";
			array[9, 1] = "System.Decimal";
			array[10, 0] = "NChar";
			array[10, 1] = "System.String";
			array[11, 0] = "NText";
			array[11, 1] = "System.String";
			array[12, 0] = "NVarChar";
			array[12, 1] = "System.String";
			array[13, 0] = "Real";
			array[13, 1] = "System.Single";
			array[14, 0] = "SmallDateTime";
			array[14, 1] = "System.DateTime";
			array[15, 0] = "SmallInt";
			array[15, 1] = "System.Int16";
			array[16, 0] = "SmallMoney";
			array[16, 1] = "System.Decimal";
			array[17, 0] = "Text";
			array[17, 1] = "System.String";
			array[18, 0] = "Timestamp";
			array[18, 1] = "System.DateTime";
			array[19, 0] = "TinyInt";
			array[19, 1] = "System.Byte";
			array[20, 0] = "UniqueIdentifer";
			array[20, 1] = "System.Guid";
			array[21, 0] = "VarBinary";
			array[21, 1] = "System.Byte[]";
			array[22, 0] = "VarChar";
			array[22, 1] = "System.String";
			array[23, 0] = "Variant";
			array[23, 1] = "System.Object";
			DBTypeConversionKey = array;
		}
	}
}
